/**
 * 
 */
package de.gee.erep.client;

import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;

import de.gee.erep.client.ui.presenter.CitizenPresenter;
import de.gee.erep.client.ui.presenter.CountryPresenter;
import de.gee.erep.client.ui.presenter.HomePresenter;
import de.gee.erep.client.ui.view.CitizenView;
import de.gee.erep.client.ui.view.CountryGridView;
import de.gee.erep.client.ui.view.HomeView;

/**
 * @author Matthew Gee created: 13.03.2011
 */
public class Environment {
	/***/
	private Model model;

	/***/
	protected class HistoryCommand implements Command {
		/***/
		private String historyToken;

		/**
		 * 
		 * @param newToken
		 *            t
		 */
		public HistoryCommand(final String newToken) {
			historyToken = newToken;
		}

		/***/
		public final void execute() {
			launch(historyToken);
		}

		/**
		 * @param historyToken
		 *            t
		 */
		private void launch(final String historyToken) {
		}
	}

	/**
	 * @param model
	 *            m
	 * @param historyToken
	 *            m
	 */
	public Environment(final Model model, final String historyToken) {
		this.model = model;
	}

	/**
	 * 
	 * @param value v
	 * @param eventBus bus
	 */
	public final void launch(final String value, final HandlerManager eventBus) {
		launch(value, null, eventBus);
	}

	/**
	 * @param token
	 *            v
	 * @param panel
	 *            p
	 * @param eventBus 
	 */
	final void launch(final String token, final Panel panel, final HandlerManager eventBus) {
		panel.clear();
		if (token.isEmpty()) {
			return;
		} else if (token.equals(CountryPresenter.PLACE)) {
			panel.add(new CountryPresenter(new CountryGridView(eventBus), this, "")
					.getDisplay().asWidget());
		} else if (token.equals(CountryPresenter.PLACE + "&Update")) {
			panel.add(new CountryPresenter(new CountryGridView(eventBus), this, "")
					.getDisplay().asWidget());
		} else if (token.equals(HomePresenter.PLACE)) {
			panel.add(new HomePresenter(new HomeView(eventBus), this, "").getDisplay().asWidget());
		} else if (token.equals(CitizenPresenter.PLACE)){
			panel.add(new CitizenPresenter(new CitizenView(RootPanel.get("con"),eventBus), this, "").getDisplay().asWidget());
		}
	}

	/**
	 * 
	 * @return model m
	 */
	public final Model getModel() {
		return model;
	}
}
